home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / cli / master60.zoo / master / batch / mvext.bat < prev    next >
Encoding:
DOS Batch File  |  1989-06-15  |  1.3 KB  |  68 lines

  1. # mvext old new
  2. # rename files with extension old to same names but extension new
  3. # first some parameter checking
  4.  
  5. alias queue 'printf "%s %s" \$1 "\$+" => \$1'
  6. alias localalias "alias \$1 \$+; queue locals \$1"
  7. alias finish 'unalias \$locals; quit'
  8. set locals queue localalias finish
  9.  
  10. ifglobal MAGIC {
  11.     nomagic
  12.     set wasmagic
  13. }
  14.  
  15. localalias getbase 'if "." in \$1 {;car -\$?c \$1;} else {cdr -0 \$1;}'
  16.  
  17. if "$1" = "-o" {
  18.     shift
  19.     set ext .$2
  20.     goto doit
  21. }
  22.  
  23. if "$3" != "" {
  24.     rem You should give maximal two parameters
  25.     goto usage
  26. }
  27.  
  28. if "$1" = "" {
  29. usage:
  30.     rem This Batchfile renames files to a different extension
  31.     rem   Usage: $0 [-o] (file pattern) [new extension]
  32.     rem Example: $0 *.doc txt
  33. # Note! : because of the parsing strategy of Master (never evaluate aliased
  34. #         expression inside a false condition) we have to put the brace on a
  35. #         seperate line. So the Master algorithm for brace-counting thinks
  36. #         this is just a local variable block.
  37.     iflocal wasmagic
  38.     {
  39.         magic
  40.     }
  41.     finish
  42. }
  43.  
  44. if "$2" != "" {
  45.     if "$2" in "$1" {
  46.         rem Don't be silly!
  47.         goto usage
  48.     }
  49.     set ext .$2
  50. } else {
  51.     set ext
  52. }
  53.  
  54. doit:
  55. files $1 => allfiles
  56.  
  57. if not err {
  58.     foreach file in allfiles do
  59.         getbase file => base
  60.         rename $file $base$ext
  61.     endfor
  62. }
  63.  
  64. iflocal wasmagic {
  65.     magic
  66. }
  67. finish
  68.